package com.leantech.android.browser.skin

import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import androidx.annotation.IntDef
import com.leantech.android.browser.R
import com.qmuiteam.qmui.skin.QMUISkinManager

object SkinManager {

    const val SkinDefault = 1
    const val SkinDark = 2

    @IntDef(
        flag = true, value = [SkinDefault, SkinDark]
    )
    @Retention(AnnotationRetention.SOURCE)
    annotation class SkinType

    fun install(context: Context) {
        val skinManager = QMUISkinManager.defaultInstance(context)
        skinManager.addSkin(SkinDefault, R.style.AppSkinDefault)
        skinManager.addSkin(SkinDark, R.style.AppSkinDark)
    }

    fun isSystemDarkModeOn(context: Context): Boolean{
        return context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
    }

    fun isDarkSkin(context: Context): Boolean{
        return currentSkin(context) == SkinDark
    }

    fun currentSkin(context: Context): Int {
        return QMUISkinManager.defaultInstance(context).currentSkin
    }

    fun currentTheme(context: Context): Resources.Theme?{
        return QMUISkinManager.defaultInstance(context).currentTheme
    }

    fun changeSkin(context: Context, @SkinType skin: Int) {
        QMUISkinManager.defaultInstance(context).changeSkin(skin)
    }

}